package com.example.springboot_jap_model.utils;

import com.example.springboot_jap_model.constant.Constant;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

/**
 * 分页
 */
public class PageableUtils {


    public static Pageable getPageable(int page,String sortStr,int size){
        Sort sort = new Sort(Sort.Direction.DESC, sortStr);
        Pageable pageable = PageRequest.of(page, size, sort);
        return pageable;
    }
    public static Pageable getPageable(int page,String sortStr){
        Sort sort = new Sort(Sort.Direction.DESC, sortStr);
        Pageable pageable = PageRequest.of(page, Constant.PAGE_SIZE, sort);
        return pageable;
    }
    public static Pageable getPageable(int page){
        Sort sort = new Sort(Sort.Direction.DESC, "id");
        Pageable pageable = PageRequest.of(page, Constant.PAGE_SIZE, sort);
        return pageable;
    }

}
